﻿using Abp.Application.Services;
using Abp.Domain.Repositories;
using Batman.Cms.Core.Models.Mvc;
using Batman.Jianbei.Forum.Core.ChatRoom;
using Batman.Jianbei.Forum.Services.ChatRoom;
using Omu.ValueInjecter;
using System.Linq;
using System.Threading.Tasks;

namespace Batman.Jianbei.Forum.Services.ChatRoom
{
    public class MaskAlbumManager : ApplicationService
    {
        public IRepository<MaskAlbum, string> AlbumRepository { get; set; }
        public IRepository<Mask, string> MaskRepository { get; set; }

        /// <summary>
        /// 保存匿名专辑
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task<ResponseBase> SaveAsync(MaskAlbumSaveInput model)
        {
            var maskAlbum = new MaskAlbum();
            maskAlbum.InjectFrom(model);

            maskAlbum = await AlbumRepository.InsertOrUpdateAsync(maskAlbum);

            if (model.Masks == null || model.Masks.Count == 0)
                return new ResponseBase();

            var masks = model.Masks.Select(t => new Mask().InjectFrom(t) as Mask).ToList();
            masks.ForEach(mask => MaskRepository.InsertOrUpdate(mask));
            return new ResponseBase();
        }
    }
}
